using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Midas.Core;
using System.Runtime.Remoting;
using System.Net;

namespace Midas.Admin
{
	public partial class LoginForm : Form
	{
		public LoginForm()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			try
			{
				Program.Manager = new AdminManager();
				Program.Sponsor = new ManagerSponsor();
				ManagerSponsor.RegisterSponsor(Program.Manager, Program.Sponsor);
				bool b = Program.Manager.Login(this.txtUser.Text, this.txtPass.Text);
				if (!b)
				{
					this.labelError.Text = "Wrong username/password combination";
					this.labelError.Visible = true;
				}
				else
				{
					this.labelError.Text = "You have successfully logged in";
					this.labelError.Visible = true;
				}
			}
			catch (MidasAlreadyLoggedInException)
			{
				this.labelError.Text = "You have already logged in.";
				this.labelError.Visible = true;
			}
			catch (RemotingException)
			{
				this.labelError.Text = "Connection/Remoting error";
				this.labelError.Visible = true;
			}
			catch (WebException)
			{
				this.labelError.Text = "Connection/Remoting error";
				this.labelError.Visible = true;
			}
		}
	}
}